/**
 *
 */
package jp.seraph.jsade.perceptor;

import jp.seraph.jsade.sexpression.Node;

/**
 *
 *
 */
public class GameStateBuilder implements PerceptorBuilder {

    /**
     *
     * @see jp.seraph.jsade.perceptor.PerceptorBuilder#build(jp.seraph.jsade.sexpression.Node)
     */
    public Perceptor build(Node aNode) {
        String tStateStr = aNode.getValue("pm");
        String tTimeStr = aNode.getValue("t");

        if (tStateStr == null || tTimeStr == null)
            throw new IllegalArgumentException("ノードの構造が想定のものと違います。");

        String tTeam = aNode.getValue("team");
        // String tUniform = aNode.getValue("unum");

        GameState tState = null;
        double tTime = 0;
        try{
            tState = GameState.getState(tStateStr);
            tTime = Double.parseDouble(tTimeStr);
        }catch(Exception e){
            e.printStackTrace();
            return new NullPerceptor();
        }

        return new GameStatePerceptor(tState, tTime, tTeam);
    }
}
